<?php
require_once("../utils/query.php");
require_Once("../config.php");
session_start(); // Remove if unnecessary, have it here to grab facebook ID;
//$name_filter = ''; // Used to filter the card images on the ftp server, as they have numbers and other characters in front of name
//$filter = ''; // Used to filter sql queries by type we want to search


$facebookID = $_SESSION['facebook_id']; 



 $drupaluid = execute_query("SELECT drupaluid FROM facebookUser WHERE facebookID = '%s'", $facebookID); // Find drupalID from facebookID

$cardList = execute_query("SELECT card_img, full_id, name, type, possessionid FROM cards_lu INNER JOIN Possession ON Possession.cardid=cards_lu.full_id WHERE front IS NULL AND userid ='%s'", '235');
//$testResult = execute_query("SELECT card_img, full_id FROM cards_lu WHERE full_id = '01-17-7'") or die ("Failed to get card list");
if ($cardList) {
	print ("cardList Worked" + $cardList);
}
else {
	mysql_error();
	echo ("cardlist failed");
}
?>
<?php
	while($row = mysql_fetch_array($cardList)) { // Put results from query in an array

		$card_img = $row[0]; // $card_img is used to identify the the card on the ftp server
		$card_id = $row[1]; // the full id
		$name = $row[2];
		$type = $row[3];
		
		
		$name = str_replace(array(' 11', ' 7', ' 3', ' 2', ' 4'), array(' 9', ' 5', ' 1', ' 1', ' 2'), $name);
			
			$color = "#ffffff";
			if ($type == 1)
				$color = "#dc3122";
			else if ($type == 2)
				$color = "#ddd327";
			else if ($type == 3)
				$color = "#0145f3";
			else if ($type == 10)
				$color = "#653b67";
				
			if(strlen($name) > 16)
			$showname = substr ($name,0,16) . "...";
			else
			$showname = $name;
			
		?>
		
		<!--	<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> -->
		<?php
		$settings = array('cardImage' => 'test');
		header('Content-type: application/json');
		echo json_encode($settings);
		switch (json_last_error()) {
        case JSON_ERROR_NONE:
            echo ' - No errors';
        break;
        case JSON_ERROR_DEPTH:
            echo ' - Maximum stack depth exceeded';
        break;
        case JSON_ERROR_STATE_MISMATCH:
            echo ' - Underflow or the modes mismatch';
        break;
        case JSON_ERROR_CTRL_CHAR:
            echo ' - Unexpected control character found';
        break;
        case JSON_ERROR_SYNTAX:
            echo ' - Syntax error, malformed JSON';
        break;
        case JSON_ERROR_UTF8:
            echo ' - Malformed UTF-8 characters, possibly incorrectly encoded';
        break;
        default:
            echo ' - Unknown error';

        break;
    }
		?>
			
		<!--	<li class="card" id="<?php echo($cardid); ?>"> 
				<li class="card" id="cardID">
			<div class="cardImg" >
				<img src="../../../card_imgs/<?php echo($card_img); ?>">
			</div>
			<div class="cardDesc" title="<?php echo($name); ?>">
					//<?php echo($showname); ?>
			</div>
		//</li>
		-->
   <?php
	}
?>

</html>